<template>
    <div class="index clearafter">
        <module-head></module-head>
        <div class="content cbafter">
            <div class="w220 fl">
                <menu-list></menu-list>
            </div>
            <div class="w980 fr">
                <div class="h1_tit">
                    <h1 class="fl">监测项目维护</h1>
                    <button class="fr default ok" @click="editmodule">新增项目</button>
                </div>
                <div class="servicepeoplelist bg">
                    <ul>
                        <li v-for = "item in programs" @click = "getInfo(item)">{{item.monitoringItemName}}</li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="modal fade bs-example-modal-lg" id="editmodule" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">监测项目编辑</h4>
                    </div>
                    <form class="form-horizontal cb" role="form" id="selectmodule" v-on:submit.prevent="savemodule">
                        <div class="modal-body">
                            <div class="form-group">
                                        <label class="col-md-3 control-label"><span class="start">*</span>项目名称:</label>
                                        <div class="col-md-6">
                                            <input type="text" class="form-control" v-model = "programParam.monitoringItemName" value = "{{programParam.monitoringItemName}}"/>
                                        </div>
                            </div>
                            <div class="form-group">
                                        <label class="col-md-3 control-label"><span class="start">*</span>项目单位:</label>
                                        <div class="col-md-6">
                                            <input type="text" class="form-control" v-model = "programParam.monitoringItemUnit"  maxlength="10"/>
                                        </div>
                            </div>
                            <div class="form-group">
                                        <label class="col-md-3 control-label"><span class="start">*</span>当前状态:</label>
                                        <div class="col-md-6" style="height: 34px;line-height: 34px;">
                                            <input id="checkbox" type="checkbox" v-model="state"  checked />&nbsp&nbsp&nbsp可用
                                        </div>
                            </div>
                        </div>

                        <div class="modal-footer savebtn">
                            <button type="submit" class="default ok center">确认</button>
                        </div>
                    </form>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
    </div>

</template>
<script>
import 'assets/lib/bootstrap-3.3.2/css/bootstrap.min.css'
import 'assets/lib/bootstrap-3.3.2/js/bootstrap.min.js'
import 'assets/reset.css'
import Public from 'assets/public.js'
import moduleHead from 'components/module-head'
import menuList from 'components/menu-list'
import bootPage from 'components/BootPage.vue'
export default {
    data() {
            return {
                
              
                programs:[],
                programParam:{
                    status:'',
                    monitoringItemName: "",
                    monitoringItemUnit: "",   
                },
                num:"",
                state:""
            }
        },
        computed: {},
        components: {
            moduleHead, menuList, bootPage
        },
        ready() {
            var that = this;
            // 获取列表
            this.findMonitoringItem();

        },
        methods: {
            
                //新增或修改弹框
                editmodule(item) {
                    var that = this;
                    $("#editmodule").modal("show");
                    $("#editmodule .modal-dialog").css("width","500px");
                    that.programParam="";
                    
                },
                //保存
                savemodule() {
                    var that=this;
                    if(this.state==true){
                        this.programParam.status=1;
                    }else{
                        this.programParam.status=0;
                    }
                     if (this.programParam.monitoringItemName==""||this.programParam.monitoringItemUnit==""||!this.programParam.monitoringItemName||!this.programParam.monitoringItemUnit) {
                         Public.ajaxPrompt('补全信息');
                     }else{
                         $.when(Public.commonajax("coms.monitoringService", "saveMonitoringItem", "["+JSON.stringify(that.programParam)+"]"))
                        .done(function(res) {
                            if (res.code == 200) {
                                Public.ajaxPrompt("保存成功");
                                $("#editmodule").modal("hide");
                                 that.findMonitoringItem();
                            } else {
                                Public.ajaxPrompt(res.msg);
                            }

                        })
                     }
                   
    
                },
                findMonitoringItem(){
                    var that = this;
                    $.when(Public.commonajax("coms.monitoringService", "findMonitoringItem", "[]"))
                .done(function(res) {
                    if (res.code == 200) {
                        that.programs = res.body;
                    }
                });
                },
               getInfo:function(item){
                var that = this;
                that.programParam="";
                 var  monitoringItemId = item.monitoringItemId;
                    $.when(Public.commonajax("coms.monitoringService", "getMonitoringItemById", "["+JSON.stringify(monitoringItemId)+"]"))
                .done(function(res) {
                    if (res.code == 200) {
                        $("#editmodule").modal("show");
                         $("#editmodule .modal-dialog").css("width","500px");
                         if (res.body.status==1) {
                            that.state =true;
                         }else{
                            that.state =false;
                         }
                         that.programParam = res.body;
                        
                    }
                });
            }
        },
        events: {
            // 分页列表数据
            'data' (data) {
                this.modulelists = data;
            },


        },
        watch: {


        },
}
</script>
<style scoped>
.servicepeoplelist {
    padding: 20px;
    height: 100%;
    overflow: hidden;
}

.servicepeoplelist li{
    float: left;
    margin-left: 10px;
    height: 50px;
    min-width: 100px;
    padding-left: 20px;
    padding-right: 20px;
    text-align: center;
    line-height: 50px;
    border-radius: 5px;
    background-color: #cccccc;
    color: white;
    margin-bottom: 10px;
}
.servicepeoplelist li:hover{
    background-color:rgb(92,192,155);
    color: #eeeeee;
}
.menuset_con {
    width: 500px;
    min-height: 644px;
    height: auto!important;
    border: 1px solid #e6e6e6;
    border-radius: 10px;
    padding-top: 30px;
    background-color: #fafafa;
}

.menuset_con_left {
    border-radius: 0 0 10px 0;
    overflow: auto;
    border-radius: 5px;
    width: 250px
}

.menuset_con_right {
    width: 570px;
    border-right: 1px #ccc solid
}

.menudetailform,
.treecon {
    border: 1px solid #ccc;
    padding: 20px 10px;
    border-radius: 5px;
    min-height: 274px;
}

.menuset_con2 {
    width: 100%;
    min-height: 400px;
    height: auto!important;
    border: none;
    border-radius: 0;
    padding-top: 30px;
    background-color: #fff;
}

.menuset_con2 .menuset_con_left {}

.menuset_con2 .menuset_con_left h3 {
    font-size: 16px;
    line-height: 40px;
    font-weight: bold;
}

.menuset_con2 .menuset_con_left input {
    padding: 10px;
}

.menuset_con2 .menuset_con_left ul li {
    line-height: 30px;
    height: 30px;
    width: 100px;
    margin: 0 auto;
}

.menuset_con2 .menuset_con_left ul li.active {
    background: #1dc499;
    border-radius: 15px;
    color: #fff
}

.menuset_con2 .menuset_con_right table th {
    background: #1dc499;
    color: #fff
}

.treecon .checkbox-inline:first-child {
    margin-left: 10px
}

.checkbox-inline {
    width: 100px
}

.centerbutton {
    width: 280px;
    margin: 0 auto;
}

.centerbutton button {
    margin-left: 5px;
    display: inline-block;
}
span.red {
    font-weight: bold;
    color: #f86448
}
</style>
